package output.input.cwiczenia;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.FileNotFoundException;

import java.text.NumberFormat;
import java.util.Date;

public class SerializacjaTester {

    @SuppressWarnings("resource")
    public static void main(String[] args) throws ClassNotFoundException {
        try {
            ObjectOutputStream os = new ObjectOutputStream(
                    new FileOutputStream(new File("obiekty.ser")));
            os.writeObject("Ala ma kota.");
            os.writeObject(new Date());
            os.writeObject(new Serializacja());
            os.close();
        } catch (IOException ex) {
            //
        }
        
        double kwota = 3121323213.2123123;
        NumberFormat formatka = NumberFormat.getCurrencyInstance();
        String wynik = formatka.format(kwota);
        System.out.println(wynik);
        System.out.println();
        wynik = NumberFormat.getCurrencyInstance().format(kwota);
        System.out.println(wynik);
        System.out.println();

        try {
            ObjectInputStream is = new ObjectInputStream(new FileInputStream(
                    new File("obiekty.ser")));
            System.out.println((String) is.readObject());
            System.out.println((Date) is.readObject());
            System.out.println((Serializacja) is.readObject());
        } catch (FileNotFoundException fnfex) {
            //
        } catch (IOException ioex) {
            //
        }
    }

}
